package com.desire.test;

import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author desire
 */
public class _10_正则 {
    public static void main(String[] args) {
        // 创建预编译正则  (建议)    后边可以跟 参数 表示 对正则的限制 (Pattern.CASE_INSENSITIVE) 忽略大小写
        Pattern regex = Pattern.compile("\\w.*", Pattern.CASE_INSENSITIVE);
        // 调用 .matcher() 传入字符串进行比较 \w 表示[a-zA-Z0-9]
        Matcher asdf = regex.matcher("asdf*12");
        // 返回 true or false
        System.out.println(asdf.matches());


        var p2 = Pattern.compile("[a-z]{1,}", Pattern.CASE_INSENSITIVE);
        var matcher = p2.matcher("java123mysql8html5javascript-Bookstudent");
        // 如果 有  则进行分组
        while (matcher.find()) {
            System.out.printf("%s ", matcher.group());
        }

        System.out.println();

        //检查字符串中有没有java  推荐使用contains
        System.out.println("java-afsdsejava0".matches(".*java.*"));
        System.out.println("java-afsdsejava0".contains("java"));

        String ss = "java8000php123python66html5css3mysql";
        String[] strings = ss.split("\\d+");
        System.out.println(Arrays.toString(strings));
        System.out.println(ss.replaceAll("\\d+", "--"));

        System.out.println();
        String a = "java8php123javascript6mysql88888html5";
        System.out.println(a);
        System.out.println(a.replaceAll("\\d+?", "-"));//?禁用贪婪
        System.out.println(a.replaceAll("\\d+", "-"));
        System.out.println("-----".repeat(30));

        //<div>java</div> 修改为 <div>java 8</div>
        String h = "java<div>hello-java</div><br><div>htm</div><span>java</span><div>java</div>java<div>hellojavascriptok</div>";
        Pattern compile = Pattern.compile("<div>[\\-a-z\\s]*?java[\\-a-z\\s]*?</div>", Pattern.MULTILINE);
        Matcher matcher1 = compile.matcher(h);
        while (matcher1.find()) {
            System.out.println(matcher1.group());
        }
        String regex2 = h.replaceAll("(<div>[\\-a-z\\s]*?)(java)([\\-a-z\\s]*?</div>)", "$1java 8$3");
        System.out.println(regex2);


        System.out.println("<><>".repeat(30));

        //转换大写 小写
        System.out.println(StringUtils.upperCase("desire"));
        System.out.println(StringUtils.lowerCase("DESIRE"));
        System.out.println(StringUtils.lowerCase("DESIRE", Locale.CANADA));

        // 大小写互换
        System.out.println(StringUtils.swapCase("LittleDesire"));

        // 判断字符串是否全部是大写或小写(空或空白符均为false)
        System.out.println(StringUtils.isAllUpperCase(null));   // false
        System.out.println(StringUtils.isAllUpperCase(""));     // false
        System.out.println(StringUtils.isAllUpperCase(" "));    // false
        System.out.println(StringUtils.isAllUpperCase("CHINA"));    // true
        System.out.println(StringUtils.isAllLowerCase(null));   // false
        System.out.println(StringUtils.isAllLowerCase(""));     // false
        System.out.println(StringUtils.isAllLowerCase(" "));    // false
        System.out.println(StringUtils.isAllLowerCase("china"));    // true


    }
}




























